﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Threading;
using YKXiangQi.Common;
using YKXiangQi.Enums;
using YKXiangQi.Models;

namespace YKXiangQi.ViewModels
{
    public class BestMovesViewModel: DockableViewModel
    {
        private ObservableCollection<BestMove> _moves;
        public ObservableCollection<BestMove> Moves
        {
            get { return _moves; }
            set
            {
                _moves = value;
                RaisePropertyChanged(() => Moves);
            }
        }

        public RelayCommand RowDoubleClickCommand { get; private set; }

        public BestMovesViewModel()
        {
            Title = "Best Moves";
            _moves = new ObservableCollection<BestMove>();    
            RowDoubleClickCommand = new RelayCommand(RowDoubleClick);
        }

        public void AddMove(BestMove move)
        {
            if (System.Windows.Application.Current != null)
                System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal,
                                                                     (Action) (() => Moves.Insert(0, move)));
        }

        public void Clear()
        {
            if (System.Windows.Application.Current != null)
                System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal,
                                                                     (Action) (() => Moves.Clear()));
        }

        public BestMove SelectedItem { get; set; }

        private void RowDoubleClick(object param)
        {
            
        }
    }
}
